package br.com.abril.sforce;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import br.com.abril.sforce.SalesForceProfile.ProfileStatus;

@Controller
public class SalesForceProfileController {

	@Autowired
	private SalesForceProfileService service;
	
	@Transactional
	@RequestMapping(value = "/rest/profiles/add", method = RequestMethod.POST)
	public @ResponseBody List<SalesForceProfile> save (@RequestBody SalesForceProfile profile) {
		service.save(profile);
		return service.findAll();
	}
	
	@RequestMapping(value = "/rest/profiles/all", method = RequestMethod.GET)
	public @ResponseBody List<SalesForceProfile> listAll() {
		return service.getRepository().findAll();
	}
	
	@RequestMapping(value = "/rest/profiles/enabled", method = RequestMethod.GET)
	public @ResponseBody SalesForceProfile getEnabledProfile() {
		return service.getCachedProfile();
	}
	
	
	
}
